package com.etl.dataflow.common.collection.queue;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @author dx
 * @since 2022/6/21
 */
public class PriorityQueueImpl<E extends Comparable<E>> implements PriorityQueue<E> {
    private final MinHeap<E> minHeap;

    public PriorityQueueImpl() {
        minHeap = new MinHeap<>();
    }

    public PriorityQueueImpl(List<E> list) {
        minHeap = new MinHeap<>(list);
    }

    public static void main(String[] args) {
        List<Integer> integers = Arrays.asList(3, 1, 2, 4, 7, 1, 8, 5);
        java.util.PriorityQueue<Integer> priorityQueue = new java.util.PriorityQueue<>();
        priorityQueue.addAll(integers);
        System.out.println(priorityQueue);
    }

    @Override
    public int getSize() {
        return minHeap.size();
    }

    @Override
    public boolean isEmpty() {
        return minHeap.isEmpty();
    }

    @Override
    public void remove(E e, Comparator<E> comparator) {
        minHeap.remove(e, comparator);
    }

    @Override
    public E getFront() {
        return minHeap.findMin();
    }

    @Override
    public void enqueue(E e, Comparator<E> keyComparator) {
        minHeap.add(e, keyComparator);
    }

    @Override
    public E dequeue() {
        return minHeap.extractMin();
    }

    @Override
    public String toString() {
        return minHeap.toString();
    }

}
